<template>
    <div class="balance-statement">
        <el-card shadow="never" class="!border-none">
            <el-alert
                title="温馨提示： 会员账户余额变动记录"
                type="success"
                :closable="false"
                show-icon
            />

            <!-- Header Form Start -->
            <el-form :model="formData" label-width="90px" inline class="mt-4">
                <el-form-item label="用户信息">
                    <el-input
                        class="w-[280px]"
                        v-model="formData.keyword"
                        placeholder="请输入用户昵称/手机号/学号"
                    />
                </el-form-item>
                <el-form-item label="变动类型">
                    <el-select v-model="formData.changeType" class="w-[280px]" placeholder="请选择">
                        <el-option label="全部" value></el-option>
                        <el-option label="管理员增加余额" :value="200"></el-option>
                        <el-option label="管理员减少余额" :value="201"></el-option>
                        <el-option label="购买课程" :value="202"></el-option>
                        <el-option label="充值余额" :value="203"></el-option>
                        <el-option label="充值赠送余额" :value="204"></el-option>
                        <el-option label="订单退款" :value="205"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="记录时间">
                    <data-picker
                        v-model:start_time="formData.startTime"
                        v-model:end_time="formData.endTime"
                    >
                    </data-picker>
                </el-form-item>
                <el-form-item>
                    <div class="m-l-20">
                        <el-button type="primary" @click="resetPage">查询</el-button>
                        <el-button @click="resetParams">重置</el-button>
                    </div>
                </el-form-item>
            </el-form>
            <!-- Header Form End -->
        </el-card>

        <el-card shadow="never" class="mt-4 !border-none">
            <!-- Main TableData Start -->
            <div class="m-t-20">
                <el-table
                    ref="tableData"
                    :data="pager.lists"
                    style="width: 100%"
                    v-loading="pager.loading"
                >
                    <el-table-column property="userSn" label="用户学号" max-width="180" />
                    <el-table-column property="nickname" label="用户昵称" min-width="140">
                        <template #default="{ row }">
                            <div class="flex items-center">
                                <el-image class="w-[40px] h-[40px]" :src="row.avatar"></el-image>
                                <div class="ml-2">{{ row.nickname }}</div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column property="mobile" label="手机号码" max-width="140" />
                    <el-table-column property="changeAmount" label="变动金额" max-width="140">
                        <template #default="scope">
                            <span v-if="scope.row.action === 1" class="red"
                                >+{{ scope.row.changeAmount }}</span
                            >
                            <span v-else>-{{ scope.row.changeAmount }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column property="leftAmount" label="剩余金额" max-width="140" />
                    <el-table-column property="chageTypeStr" label="变动类型" max-width="140" />
                    <el-table-column property="associationSn" label="来源" max-width="140" />
                    <el-table-column property="createTime" label="记录时间" max-width="140" />
                </el-table>
            </div>
            <!-- Main TableData End -->

            <!-- Footer Pagination Start -->
            <div class="flex justify-end mr-2">
                <pagination v-model="pager" @change="getLists" />
            </div>
            <!-- Footer Pagination End -->
        </el-card>
        <layout-footer></layout-footer>
    </div>
</template>

<script lang="ts" setup>
import { apiAccountLogLists } from '@/api/finance/finance'
import { ref } from 'vue'
import Pagination from '@/components/pagination/index.vue'
import { usePaging } from '@/hooks/usePaging'
import DataPicker from '@/components/data-picker/index.vue'
import LayoutFooter from '@/layout/components/footer.vue'

/** Interface Start **/
interface FormDataObj {
    sn: string // 变动编号
    keyword: string // 昵称搜索
    changeType: number | string // 变动类型
    startTime: string // 记录开始时间
    endTime?: string // 记录结束时间
}
/** Interface End **/

/** Data Start **/
const otherLists = ref({})
// 表单数据
const formData = ref<FormDataObj>({
    sn: '',
    keyword: '',
    changeType: '',
    startTime: '',
    endTime: ''
})
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiAccountLogLists,
    params: formData.value
})
/** Data End **/

/** LifeCycle Start **/
getLists()
/** LifeCycle End **/
</script>

<style lang="scss" scoped>
.ls-input {
    width: 170px;
}

.red {
    color: red;
}
.el-alert--success.is-light {
    background-color: #edefff;
    color: #4a5dff;
}
</style>
